﻿using System;

namespace ControlCenterService
{
	class EmailUtilities
	{
		public bool sendEmail(string smtpHost, string targetAddressList, string sourceAddress, string emailSubject, string emailMessage)
		{
			bool success = false;
			try
			{
				string[] targetAdressses = targetAddressList.Split(';');
                if (!String.IsNullOrWhiteSpace(targetAddressList))
				{
					System.Diagnostics.Debug.WriteLine(Environment.UserDomainName);
					System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
					//message.To.Add("luckyperson@online.microsoft.com");
					foreach (string targetAddress in targetAdressses)
					{
                        if (!String.IsNullOrWhiteSpace(targetAddress))
                        {
                            message.To.Add(targetAddress);
                        }
					}
					message.Subject = emailSubject;
					message.From = new System.Net.Mail.MailAddress(sourceAddress);
					message.Body = emailMessage;
					System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(smtpHost);
                    if (message.To.Count > 0)
                    {
                        smtp.Send(message);
                        success = true;
                    }
				}
			}
			catch (Exception exception)
			{
				success = false;
				System.Diagnostics.Debug.WriteLine(string.Format("{0}: {1}", exception.Message, exception.InnerException));
			}
			return success;
		}
	}
}
